<?php
include_once '../Login/databaseconnection.php';
$Lab_Type=$_POST['Lab_Type'];
$New_Lab_Type=$_POST['New_Lab_Type'];
$Lab_Category=$_POST['Lab_Category'];
$New_Lab_Category=$_POST['New_Lab_Category'];
$Special_Projects=$_POST['Special_Projects'];
$S_Pro="";
$S_Proje="";

 $Lab_Id=$_SESSION['Lab_Id'];
$School_Id=$_SESSION['School_Id'];
$_SESSION['La_Id']=$_SESSION['Lab_Id'];
$_SESSION['Scho_Id']=$_SESSION['School_Id'];
$Lab_Id1=$_POST['Lab_Id1'];
$School_Name=$_POST['School_Id'];
$sch_name=mysql_query("SELECT * FROM school WHERE Name='$School_Name'");
if($sn=mysql_fetch_array($sch_name))
{
$School_Id1=$sn['School_Id'];
}
$Source_Of_Power=$_POST['Source_Of_Power'];
$Tp_Number=$_POST['Tp_Number'];
     $Account_Number=$_POST['Account_Number'];
$Date_of_commencement=$_POST['Date_of_commencement'];
 $Availability_Of_LAN=$_POST['Availability_Of_LAN'];
  $LAN_Supplier=$_POST['LAN_Supplier'];
   $Supplied_Date=$_POST['Supplied_Date'];
    $Speed_Of_WAN=$_POST['Speed_Of_WAN'];
     $WAN_Connection_Type=$_POST['WAN_Connection_Type'];
	 $Wired_Date=$_POST['Wired_Date'];
$Internet_Facilities=$_POST['Internet_Facilities'];
for($i=0;$i<sizeof($Special_Projects);$i++)
  {
  if($i==0)
  {
   if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro="other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro="other_".$spe_other;
  }
  }
  else
  {
  $S_Pro=$Special_Projects[0];
  }
  }
   else
  {
    if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro=$S_Pro.",other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro=$S_Pro.",other_".$spe_other;
  }
  }
  else
  {
	$S_Pro=$S_Pro.",".$Special_Projects[$i];
	}
	}
	 }
if($New_Lab_Type!=""&&$Lab_Type!="Select One")
	{
$_SESSION['error']="Please select or type the lab's type!";
	}
	else if($New_Lab_Category!=""&&$Lab_Category!="Select One")
	{
$_SESSION['error']="Please select or type the lab's type!";
	}
	else
	{
	if($New_Lab_Type!="")
	{
	$Lab_Type=$New_Lab_Type;
	}
	if($New_Lab_Category!="")
	{
	$Lab_Category=$New_Lab_Category;
	}
  date_default_timezone_set("Europe/Paris");
    $t_d=date("Y/m/d");
    $resultnet=mysql_query("SELECT * FROM network WHERE School_Id='$School_Id' AND Lab_Id='$Lab_Id'");
   if($rownet=mysql_fetch_array($resultnet))
{
	$Availability_Of_LAN0=$rownet['Availability_Of_LAN '];
    $LAN_Supplier0=$rownet['LAN_Supplier'];
    $Supplied_Date0=$rownet['Supplied_Date'];
    $Speed_Of_WAN0=$rownet['Speed_Of_WAN'];
    $WAN_Connection_Type0=$rownet['WAN_Connection_Type'];
	$Wired_Date0=$rownet['Wired_Date'];
	$Internet_Facilities0=$rownet['Internet_Facilities'];
	}
	   $resultl=mysql_query("SELECT * FROM lab WHERE School_Id='$School_Id' AND Lab_Id='$Lab_Id'");
   if($rowl=mysql_fetch_array($resultl))
{
	$Account_Number0=$rowl['Account_Number'];
	}
		if($Lab_Type==""||$Lab_Id1==""||$School_Id1==""||$Source_Of_Power==""||$Tp_Number==""||$Date_of_commencement==""||$Availability_Of_LAN==""||$Internet_Facilities=="")
  {
	  $_SESSION['errorin']="Please check your inputs some of them are null!";
  }
 	if($Lab_Type!=""&&$Lab_Id1!=""&&$School_Id1!=""&&$Source_Of_Power!=""&&$Tp_Number!=""&&$Date_of_commencement!=""&&$Availability_Of_LAN!=""&&$Internet_Facilities!="")
  {
 if(($Account_Number0!=""&&$Account_Number=="")||($LAN_Supplier0!=""&&$LAN_Supplier=="")||($Supplied_Date0!=""&&$Supplied_Date=="")||($Speed_Of_WAN0!=""&&$Speed_Of_WAN=="")||($WAN_Connection_Type0!=""&&$WAN_Connection_Type=="")||($Wired_Date0!=""&&$Wired_Date=="")||($Internet_Facilities0!=""&&$Internet_Facilities==""))
 {
 $_SESSION['errorempt']="You have deleted some values If you want to put them,Please update again!";
  }
  if($S_Proje=="yes")
  {
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
	  if($spe_other!="")
  {
  $sql=mysql_query("UPDATE lab SET Lab_Category='$Lab_Category',Special_Project='$S_Pro',School_Id='$School_Id1',Lab_Id='$Lab_Id1',Lab_Type='$Lab_Type',Source_Of_Power='$Source_Of_Power',Tp_Number='$Tp_Number',Account_Number='$Account_Number',Date_of_commencement='$Date_of_commencement',Last_Updated_Date='$t_d' WHERE School_Id='$School_Id' AND Lab_Id='$Lab_Id'");
$sqln=mysql_query("UPDATE network SET School_Id='$School_Id1',Lab_Id='$Lab_Id1',Availability_Of_LAN='$Availability_Of_LAN',Speed_Of_WAN='$Speed_Of_WAN',LAN_Supplier='$LAN_Supplier',Supplied_Date='$Supplied_Date',WAN_Connection_Type='$WAN_Connection_Type',Wired_Date='$Wired_Date',Internet_Facilities='$Internet_Facilities',Last_Updated_Date='$t_d' WHERE School_Id='$School_Id' AND Lab_Id='$Lab_Id'");
unset($_SESSION['Lab_Id']);
unset($_SESSION['School_Id']);
if($sql)
  {
 $_SESSION['error']="This record is successfully updated!<br/>";
  if($LAN_Supplier==""||$Availability_Of_LAN==""||$Supplied_Date==""||$Speed_Of_WAN==""||$WAN_Connection_Type==""||$Wired_Date=="")
  {
    $_SESSION['error']=$_SESSION['error']."And some Network details are null";
  $sqlnet=mysql_query("INSERT INTO network(Lab_Id,School_Id,Availability_Of_LAN,LAN_Supplier,Speed_Of_WAN,Supplied_Date,WAN_Connection_Type,Wired_Date,Internet_Facilities,Last_Updated_Date)values('$Lab_Id1','$School_Id1','$Availability_Of_LAN','$LAN_Supplier','$Speed_Of_WAN','$Supplied_Date','$WAN_Connection_Type','$Wired_Date','$Internet_Facilities','$t_d')");
if($sqlnet)
{ 
 $_SESSION['error']=$_SESSION['error'].",Now they are stored!";
  }
   if(!$sqln)
  {
 $_SESSION['error']=$_SESSION['error'].", unable to update the network details!<br/>";
}
  }
  }
  if(!$sql)
  {
 $_SESSION['error']="Sorry unable to update the lab's basic details!<br/>";
}
 }
 else
 {
  $_SESSION['error']="Please type the other special project!<br/>";
 }
 }
 else
 {
 $sql=mysql_query("UPDATE lab SET Lab_Category='$Lab_Category',Special_Project='$S_Pro',School_Id='$School_Id1',Lab_Id='$Lab_Id1',Lab_Type='$Lab_Type',Source_Of_Power='$Source_Of_Power',Tp_Number='$Tp_Number',Account_Number='$Account_Number',Date_of_commencement='$Date_of_commencement',Last_Updated_Date='$t_d' WHERE School_Id='$School_Id' AND Lab_Id='$Lab_Id'");
$sqln=mysql_query("UPDATE network SET School_Id='$School_Id1',Lab_Id='$Lab_Id1',Availability_Of_LAN='$Availability_Of_LAN',Speed_Of_WAN='$Speed_Of_WAN',LAN_Supplier='$LAN_Supplier',Supplied_Date='$Supplied_Date',WAN_Connection_Type='$WAN_Connection_Type',Wired_Date='$Wired_Date',Internet_Facilities='$Internet_Facilities',Last_Updated_Date='$t_d' WHERE School_Id='$School_Id' AND Lab_Id='$Lab_Id'");
unset($_SESSION['Lab_Id']);
unset($_SESSION['School_Id']);
if($sql)
  {
 $_SESSION['error']="This record is successfully updated!<br/>";
  if($LAN_Supplier==""||$Availability_Of_LAN==""||$Supplied_Date==""||$Speed_Of_WAN==""||$WAN_Connection_Type==""||$Wired_Date=="")
  {
    $_SESSION['error']=$_SESSION['error']."And some Network details are null";
  $sqlnet=mysql_query("INSERT INTO network(Lab_Id,School_Id,Availability_Of_LAN,LAN_Supplier,Speed_Of_WAN,Supplied_Date,WAN_Connection_Type,Wired_Date,Internet_Facilities,Last_Updated_Date)values('$Lab_Id1','$School_Id1','$Availability_Of_LAN','$LAN_Supplier','$Speed_Of_WAN','$Supplied_Date','$WAN_Connection_Type','$Wired_Date','$Internet_Facilities','$t_d')");
if($sqlnet)
{ 
 $_SESSION['error']=$_SESSION['error'].",Now they are stored!";
  }
   if(!$sqln)
  {
 $_SESSION['error']=$_SESSION['error'].", unable to update the network details!<br/>";
}
  }
  }
  if(!$sql)
  {
 $_SESSION['error']="Sorry unable to update the lab's basic details!<br/>";
}
}
 }
  }
?>